<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('【设备】列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label class="font-noraml">设备名称：</label>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <label>设备串口：</label>
                            <input type="text" name="serialPort"/>
                        </li>
                        <li>
                            <label>比特率：</label>
                            <input type="text" name="bitRate"/>
                        </li>
                        <li>
                            <label class="font-noraml">设备运行状态：</label>
                            <!--<input type="text" name="state"/>-->
                            <select class='form-control' name='state' >
                                <option value="">全部</option>
                                <option value="1" >已停止</option>
                                <option value="2" >正在运行</option>
                            </select>
                        </li>
                        <li>
                            <label>设备运行时间：</label>
                            <input type="text" class="time-input" placeholder="请选择设备运行时间" name="runTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:device:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:device:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:device:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-success" onclick="sendPortDate('pupm on')" shiro:hasPermission="system:device:add">
                <i class="fa fa-plus"></i> 开始抽真空
            </a>
            <a class="btn btn-success" onclick="sendPortDate('pupm off')" shiro:hasPermission="system:device:add">
                <i class="fa fa-plus"></i> 停止抽真空
            </a>
            <a class="btn btn-success" onclick="sendPortDate('temp1 on')" shiro:hasPermission="system:device:add">
                <i class="fa fa-plus"></i> 启动样品仓1温控
            </a>
            <a class="btn btn-success" onclick="sendPortDate('temp1 off')" shiro:hasPermission="system:device:add">
                <i class="fa fa-plus"></i> 关闭样品仓1温控
            </a>
            <a class="btn btn-success" onclick="sendPortDate('temp2 off')" shiro:hasPermission="system:device:add">
                <i class="fa fa-plus"></i> 启动样品仓2温控
            </a>
            <a class="btn btn-success" onclick="sendPortDate('temp2 off')" shiro:hasPermission="system:device:add">
                <i class="fa fa-plus"></i> 关闭样品仓2温控
            </a>
            <a class="btn btn-success" onclick="sendPortDate('val1 go1')" shiro:hasPermission="system:device:add">
                <i class="fa fa-plus"></i> 阀1走到1位置
            </a>
            <a class="btn btn-success" onclick="sendPortDate('val1 go2')" shiro:hasPermission="system:device:add">
                <i class="fa fa-plus"></i> 阀1走到2位置
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>


    </div>
    <!--<div class="row">
        <div class="col-sm-12 select-table table-striped">
            &lt;!&ndash; 点击事件的方式打开使用 detailViewIcon: false and detailViewByClick: true
                 data-detail-view-icon="false"
                 data-detail-view-by-click="true" &ndash;&gt;
            <table id="bootstrap-table"></table>
        </div>
    </div>-->
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:device:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:device:remove')}]];
    var prefix = ctx + "system/device";
    var detail_prefix = ctx + "system/details";
    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "【设备列表】",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            //detailView: true,
            /*onExpandRow : function(index, row, $detail) {
                initChildTable(index, row, $detail);
            },*/
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '设备id',
                    visible: false
                },
                {
                    field: 'name',
                    title: '设备名称'
                },
                {
                    field: 'serialPort',
                    title: '设备串口'
                },
                {
                    field: 'bitRate',
                    title: '比特率'
                },
                {
                    field: 'state',
                    title: '设备运行状态'
                },
                {
                    field: 'runTime',
                    title: '设备运行时间'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="startPort(\'' + row.id + '\')"><i class="fa fa-edit"></i>启动串口</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function addjh(id){
        var options = {
            title: 'aa',
            width: "800",
            height: "800",
            url: prefix + "/add/"+id,
            callBack: addSave
        };
        $.modal.openOptions(options);
    }
    function addSave(index,layero){
        layero.find("iframe")[0].contentWindow.submitHandler();
    }
    function startPort(id) {
        $.ajax({
            url: detail_prefix + "/startPort",
            type: "post",
            dataType: "json",
            success: function(data) {
                // 处理成功的响应
                console.log(data);
            },
            error: function(error) {
                // 处理错误的响应
                console.log(error);
            }
        });
    }
    function sendPortDate(dat) {
        $.ajax({
            url: detail_prefix + "/sendPortDate/"+dat,
            type: "post",
            dataType: "json",
            success: function(data) {
                // 处理成功的响应
                console.log(data);
            },
            error: function(error) {
                // 处理错误的响应
                console.log(error);
            }
        });
    }
</script>
</body>
</html>